import request, { type ListQuery, type ListResponse } from "@/utils/request";

const FIELD_BASE_URL = "/api";

export const FieldAPI = {
  getFieldList: (params: FieldListParams) => {
    return request.get<any, ListResponse<FieldType>>(`${FIELD_BASE_URL}/internal/SystemConfig/`, {
      params,
    });
  },
  fieldDetail: (id: number) => {
    return request.get<any, FieldType>(`${FIELD_BASE_URL}/internal/SystemConfig/${id}/`);
  },
  addField: (data: Partial<FieldType>) => {
    return request.post(`${FIELD_BASE_URL}/internal/SystemConfig/`, data);
  },
  updateField: (data: Partial<FieldType>) => {
    return request.put(`${FIELD_BASE_URL}/internal/SystemConfig/${data.id}/`, data);
  },
  deleteField: (id: number) => {
    return request.delete(`${FIELD_BASE_URL}/internal/SystemConfig/${id}/`);
  },
};

export type FieldListParams = {} & ListQuery;

export type FieldType = {
  id: number;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  key: string;
  value: string;
  description: string;
  is_public: boolean;
};

export default FieldAPI;
